<?php

namespace App\Presenters;

use App\Transformers\RoleTransformer;
use Prettus\Repository\Presenter\FractalPresenter;
use App\Repositories\RoleRepositoryEloquent;

/**
 * Class RolePresenter
 *
 * @package namespace App\Presenters;
 */
class RolePresenter extends FractalPresenter
{
    protected $role;

    public function __construct(RoleRepositoryEloquent $role)
    {
        $this->role = $role;
    }

    /**
     * Transformer
     *
     * @return \League\Fractal\TransformerAbstract
     */
    public function getTransformer()
    {
        return new RoleTransformer();
    }

    /**
     *  Roles checkbox
     * @param array $roles
     * @return string
     */
    public function rolesCheckbox($hasRoles = [])
    {
        $roles = $this->role->all();
        $checkbox = '';
        foreach ($roles as $role)
        {
            if (in_array($role->name,$hasRoles))
            {
                $checkbox .= '<div class="checkbox checkbox-primary checkbox-single"><input type="checkbox" checked="checked" name="roles[]" value="'.$role->id.'" id="id-'.$role->id.'"><label for="id-'.$role->id.'">'.$role->name.'</label></div>';
            }
            else
            {
                $checkbox .= '<div class="checkbox checkbox-primary checkbox-single"><input type="checkbox" name="roles[]" value="'.$role->id.'" id="id-'.$role->id.'""><label for="id-'.$role->id.'"">'.$role->name.'</label></div>';
            }
        }
        return $checkbox;
    }
}
